/*
 * inverse_normal_distribution.hpp
 *
 *  Created on: Mar 13, 2009
 *      Author: Lev
 */

#ifndef INVERSE_NORMAL_DISTRIBUTION_HPP_
#define INVERSE_NORMAL_DISTRIBUTION_HPP_

#include <stdexcept>
#include <utility>

class InverseNormalCDF {
private:
	double _mean;
	double _rms;
	double approximation4LowerRegion( const double &p ) const;
	double approximation4CentralRegion( const double &p ) const;
	double approximation4UpperRegion( const double &p ) const;
public:
	InverseNormalCDF( const double &mean, const double &rms ) throw();
	InverseNormalCDF( const InverseNormalCDF &other ) throw();
	InverseNormalCDF& operator= ( const InverseNormalCDF &other ) throw();
	bool operator== ( const InverseNormalCDF &other ) const throw();
	double approximation( const double &p ) const
		throw(std::invalid_argument);
};

class ConfidenceInterval {
private:
	double _mean;
	double _rms;
	double _confidence;
	double _lMargin;
	double _rMargin;
	InverseNormalCDF _invNormCDF;
public:
	ConfidenceInterval( const double &mean, const double &rms, const double &confidence )
		throw(std::invalid_argument);
	ConfidenceInterval( const ConfidenceInterval& other ) throw();
	ConfidenceInterval& operator= ( const ConfidenceInterval& other ) throw();
	bool operator== ( const ConfidenceInterval& other ) const throw();
	inline double getConfidence() const { return _confidence; }
	std::pair<double, double> getInterval() const;
	inline double getLeftMargin() const { return _lMargin; }
	inline double getRightMargin() const { return _rMargin; }
	inline std::pair<double, double> getMargins() const;
	ConfidenceInterval& recalculate( const double &confidence )
		throw(std::invalid_argument);
};

#endif /* INVERSE_NORMAL_DISTRIBUTION_HPP_ */
